package com.icss.clothes.mapper;

import com.icss.clothes.entity.Buy;
import com.icss.clothes.entity.Collection;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 购物车的Mapper
 */
@Mapper
public interface BuyMapper {
    //添加购物车
    @Insert("insert into car(c_id,cd_id,user_id,quantity,totalPrice) values(#{c_id},#{cd_id},#{user_id},#{quantity},#{totalPrice})")
    public void addCar(Buy buy);

    //查询要添加到购物车中的商品是否已经存在
    @Select("select car.* from car where cd_id=#{cd_id} and user_id=#{user_id}")
    public Buy findSameShopInShop(@Param("cd_id") int cd_id,
                                  @Param("user_id") int user_id);

    //更改购物车中商品的数量
    @Update("update car set quantity=quantity+#{quantity} where car_id=#{car_id}")
    public void updateShopQuantity(@Param("car_id") int car_id,
                                   @Param("quantity") int quantity);

    //查看购物车列表
    @Select("select c_picture2,c_name,c_price,quantity,totalPrice,car.c_id,s.size_name,col.color_name,car_id " +
            "from car join commodity c on c.c_id=car.c_id join commodity_detail cd" +
            " on car.cd_id=cd.cd_id left outer join size s on s.size_id=cd.size_id " +
            "left outer join color col on col.color_id=cd.color_id " +
            "where user_id=#{user_id}")
    public List<Buy> findCarList(int user_id);

    //通过指定的购物车编号查询购物车信息
    @Select("select * from car where car_id=#{car_id}")
    public Buy selectAllByCar_id(int car_id);
    //删除购物车
    @Delete("delete from car where car_id=#{car_id}")
    public void deleteCarByCar_id(int car_id);

    //用于头部购物车展示
    @Select("select c_picture2,c_name,c_price,quantity,totalPrice,car.c_id,s.size_name,col.color_name,car_id " +
            "from car join commodity c on c.c_id=car.c_id join commodity_detail cd" +
            " on car.cd_id=cd.cd_id left outer join size s on s.size_id=cd.size_id " +
            "left outer join color col on col.color_id=cd.color_id " +
            "where user_id=#{user_id} limit 0,3")
    public List<Buy> findCarListInTop(int user_id);
}
